package com.spirng.leetcode.day08;

import com.spirng.leetcode.day07.Test106;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Test77 {
    public static void main(String[] args) {
        Test77 test77 = new Test77();
        test77.combine(4,2);
    }
    ArrayList arrayList=new ArrayList<List<Integer>>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
          backtracking(n,k,1);
        return arrayList;
    }
    public void backtracking(int n,int k,int offSize){
        if(path.size()==k){
            arrayList.add(new ArrayList<>(path));
            return;
        }
        for (int i = offSize; i <= n-(k-path.size())+1 ; i++) {
            path.add(i);
            backtracking(n,k,i+1);
            path.removeLast();
        }
    }
}
